﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using hcom;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;

namespace hcms.Admin
{
	public partial class CommentEdit : System.Web.UI.Page
	{
		protected string submitstate;	// 提示语
		protected string comid;	// 评论id。
		private hString hstr = new hString();
		private Model model = Global.model;
		protected string artUrl;
		protected string artTitle;
		protected void Page_Load(object sender, EventArgs e)
		{
			comid = Request["comid"];
			
			if (IsPostBack)
			{
				switch (cmd.Value)
				{
					case "save":
						save();
						break;
					default:
						throw (new Exception("不可识别的命令: \"" + cmd.Value + "\""));
				}
			}

			DataRow row = model.getCommentByID(comid);
			idcomment.Value = row["comComment"].ToString();	// 评论内容
			idlevel.Value = row["comLevel"].ToString();	// 文档级别，越大越靠前

			string aid = row["comArticleID"].ToString();
			row = model.getArticleByID(aid);
			artTitle = row["artTitle"].ToString();

			DataRowCollection rows = model.getColumnsByAid(aid);
			artUrl = string.Format("/Articles/{0}-{1}.htm", rows[0]["colID"], aid);
	
		}

		private void save()
		{
			string strsql = string.Format("UPDATE hcms_Comments SET comComment='{0}', " +
				"comLevel={1}" +
				" WHERE comID = '{2}'",
				hstr.ToSQL(idcomment.Value),
				hstr.ToSQL(idlevel.Value),
				comid
				);
			model.da.Execute(strsql);

			submitstate = "保存完毕";
		}


	}
}